
/*
  (C) 2009 Vasiliy Chekurov
*/

#include "kernel.h"
#include "wnd.h"
#include "file.h"

Kernel::Kernel()
{
  m_wnd = 0;
  m_file = 0;
}

Kernel::~Kernel()
{
}

bool Kernel::Open(HINSTANCE hInstance, HINSTANCE prevInstance, LPSTR lpCmdLine, int nCmdShow)
{
  m_wnd = new Wnd;
  if ( m_wnd )
    if ( !m_wnd->Open(hInstance, prevInstance, lpCmdLine, nCmdShow) )
      return false;

  m_file = new File;
  
  return true;
}

int Kernel::Open(int argc, const char** argv)
{
  return 1;
}

void Kernel::Close()
{
  if ( m_wnd )
  {
    m_wnd->Close();
    delete m_wnd;
    m_wnd = 0;
  }
  if ( m_file )
  {
    delete m_file;
    m_file = 0;
  }
}

void Kernel::Run()
{
  bool flag = true;

	// main loop
  while( flag )
  {
    int state, result;
    
    result = m_wnd->Run();
    state = m_wnd->GetState();
    
    if ( state != STATE_RUN ) flag = false;
  }

}
